package com.zyg.service.impl;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.core.userdetails.User;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.security.core.userdetails.UserDetailsService;
import org.springframework.security.core.userdetails.UsernameNotFoundException;
import org.springframework.security.crypto.password.PasswordEncoder;
import org.springframework.stereotype.Service;

import java.util.Collections;

@Service
public class CustomUserDetailsService implements UserDetailsService {
    @Autowired
    private PasswordEncoder passwordEncoder;

    @Override
    public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException {
        // Replace this with actual database call
        //这个可以在库中查询验证，这里就简单写一下
        //之前单点登录是定义一个类实现UserDetails，原来可以直接new的这个user类，太离谱了原来本来就有
        if ("admin".equals(username)) {
            return new User("admin", passwordEncoder.encode("123"), Collections.emptyList()); // 密码应加密存储
        }
        throw new UsernameNotFoundException("User not found");
    }
}
